package huzh.foundation.pool;

import java.util.Stack;

/**
 *<p>title:ListElementPool</p>
 *<p>description:</p>
 * @since 2014-6-7
 * @author huzh
 * @version 1.0
 */
public class ListElementPool {
    /**pool*/
    private Stack<ListElement> pool = null;
    /**max_size*/
    private int max_size = 0;

    /**
     * @param max_size
     */
    public ListElementPool(int max_size) {
        this.pool = new Stack<ListElement>();
        this.max_size = max_size;
    }

    /**
     * @return
     */
    public ListElement getElement() {
        if (this.pool.size() == 0) {
            return new ListElement();
        }
        return (ListElement)this.pool.pop();
    }

    /**
     * @param el
     */
    public void returnElement(ListElement el){
        if (this.pool.size() < this.max_size){
            el.setNext(null);
            el.setData(null);
            this.pool.push(el);
        }
    }
}
